/*
Copyright (c) 2025 HeZongLun
NahidaProject is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan
PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

#pragma once

#ifdef _WIN32
#define ExportSymbol  __declspec(dllexport)
#else
#define ExportSymbol
#endif

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <filesystem>
#include <stdexcept>
#include <algorithm>
#include <iterator>

namespace fs = std::filesystem;

namespace NahidaProject {
	class ExportSymbol FileHelper {
	private:
		std::string fileName;
		mutable std::fstream file;

	public:
		explicit FileHelper(const std::string& fileName = "") : fileName(fileName) {}

		~FileHelper() {
			if (file.is_open()) {
				file.close();
			}
		}

		void SetFilename(const std::string& fileName);
		std::string GetFilename() const;
		bool Exists() const;
		bool CreateFile() const;
		void WriteText(const std::string& content) const;
		void AppendText(const std::string& content) const;
		void WriteLines(const std::vector<std::string>& lines) const;
		std::string ReadWholeText() const;
		std::vector<std::string> ReadLines() const;
		std::vector<char> ReadBinary() const;
		void WriteBinary(const std::vector<char>& data) const;
		static bool CopyFile(const std::string& source, const std::string& destination);
		static bool MoveFile(const std::string& source, const std::string& destination);
		static bool DeleteFile(const std::string& fname);
		std::uintmax_t GetFileSize() const;
		std::time_t GetLastModified() const;
		void ClearFile() const;
		bool IsEmpty() const;
		static bool CreateDirectory(const std::string& dirPath);
		static std::vector<std::string> ListFiles(const std::string& dirPath);
	private:
		void ValidateFilename() const;
	};
}
